package com.pybox.api;

import com.pybox.aop.Mylog;
import com.pybox.dto.IOTaskDto;
import com.pybox.dto.Result;
import com.pybox.entity.TChangNameDan;
import com.pybox.service.TChangNameDanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.history.HistoricActivityInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.Map;

/**
 * @author LeiYang
 * @title: TWorkflowApi
 * @projectName pybox
 * @description: TODO
 * @date 2019/7/3012:29
 */

@RequestMapping("/TChangeNameDanApi")
@Api(tags = "TChangeNameDanApi")
@Slf4j
@RestController
public class TChangeNameDanApi {

    @Autowired
    private TChangNameDanService tChangNameDanService;


    /**
     *  @ApiOperation(value = "改名申请单开始审核流程", notes = "改名申请单开始审核流程(申请单)")
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "改名申请单开始审核流程", notes = "改名申请单开始审核流程(申请单)")
    @RequestMapping(value = "/save", method = RequestMethod.PUT)
    @Mylog(value = "改名申请单开始审核流程")
    @ApiIgnore
    public Result<Boolean> save(@RequestBody TChangNameDan dto) {

        tChangNameDanService.save(dto);

        return Result.ok(true);
    }


    /**
     * 分页查询申请单
     */

    @ApiOperation(value = "分页查询TObjects", notes = "分页查询TObjects")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "t_status", value = "t_status", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "reason_id", value = "reason_id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "beforname", value = "beforname", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "ctime", value = "ctime", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "utime", value = "utime", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TChangNameDan>> page(
            @RequestParam(required = false) String t_status,
            @RequestParam(required = false) String reason_id,
            @RequestParam(required = false) String beforname,
            @RequestParam(required = false) String type,
            @RequestParam(required = false) String ctime,
            @RequestParam(required = false) String utime,
            @RequestParam Integer pageNo,
            @RequestParam Integer pageSize) {

        Map<String, String> params = new HashMap<>();

        params.put("t_status", t_status);
        params.put("ctime", ctime);
        params.put("utime", utime);
        params.put("beforname", beforname);
        params.put("reason_id", reason_id);
        params.put("type", type);

        return Result.ok(tChangNameDanService.page(pageNo, pageSize, params));
    }

    /**
     * 根据Id查询申请单
     */

    @ApiOperation(value = "查询TChangNameDan", notes = "根据id查询TChangNameDan(申请单)")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "TChangNameDan id", dataType = "Integer", paramType = "path")
    public Result<TChangNameDan> detail(@PathVariable("id") Integer id) {

        return Result.ok(tChangNameDanService.detail(id));
    }


    /**
     * 修改申请单
     */
    @ApiOperation(value = "更新TChangNameDan", notes = "更新TChangNameDan")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    @Mylog(value = "更新了改名申请单")
    @ApiImplicitParam(name = "id", value = "TChangNameDan id", dataType = "String", paramType = "path")
    public Result<Boolean> update(@PathVariable("id") Integer id, @RequestBody TChangNameDan dto) {
        tChangNameDanService.update(id, dto);
        return Result.ok(true);
    }


    /**
     * 删除申请单
     */
    @ApiOperation(value = "删除TChangNameDan", notes = "根据id删除TChangNameDan(申请单)")
    @Mylog(value = "删除了改名申请单信息")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ApiImplicitParam(name = "id", value = "TChangNameDan id", dataType = "String", paramType = "path")
    public Result<Boolean> delete(@PathVariable("id") Integer id) {
        tChangNameDanService.delete(id);
        return Result.ok(true);
    }


    /**
     * 改名申请单开始审核流程 ,更新改名申请单状态，启动流程实例，让启动的流程实例关联业务
     */
//    @ApiOperation(value = "改名申请单开始审核流程", notes = "改名申请单开始审核流程(申请单)")
//    @RequestMapping(value = "/startWorkflew", method = RequestMethod.PUT)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "taskId", value = "申请单 taskId", dataType = "Integer", paramType = "query"),
//            @ApiImplicitParam(name = "user_id", value = "下一步审核人ID", dataType = "Integer", paramType = "query")})
//    public Result<Boolean> startWorkflew(@RequestParam("id") Integer id,@RequestParam("user_id") Integer user_id) {
//        tChangNameDanService.startWorkflew(id,user_id);
//        //log.info("::"+taskId+"::"+user_id);
//        return Result.ok(true);
//    }

    /**
     * 分页查询当前用户的任务表，根据Id
     */

    @ApiOperation(value = "分页查询前用户的任务表", notes = "分页查询前用户的任务表")
    @RequestMapping(value = "/searchTask", method = RequestMethod.GET)
    public Result<Page<IOTaskDto>> pageQuerTask(
            @RequestParam Integer pageNo,
            @RequestParam Integer pageSize) {
        return Result.ok(tChangNameDanService.page(pageNo, pageSize));
    }


    /**一：使用任务ID，查找请假单ID，从而获取请假单信息*/

    @ApiOperation(value = "使用任务ID，查找请假单ID，从而获取请假单信息", notes = "使用任务ID，查找请假单ID，从而获取请假单信息")
    @RequestMapping(value = "/detailChangNameDan/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "task id", dataType = "String", paramType = "path")
    public Result<TChangNameDan> detailChangNameDan(@PathVariable("id") Integer taskId) {
        return Result.ok(tChangNameDanService.detailChangNameDan(taskId));
    }


    /**
     * 根据taskId处理这条信息
     */
    @ApiOperation(value = "根据taskId处理这条信息", notes = "根据taskId处理这条信息")
    @RequestMapping(value = "/dealTask/{id}", method = RequestMethod.PUT)
    @Mylog(value = "处理了申请任务")
    @ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "path")
    public Result<Boolean> dealTask(@PathVariable("id") Integer id, @RequestBody TChangNameDan dto) {
        tChangNameDanService.dealTask(id, dto);
        return Result.ok(true);
    }

    /**
     * 根据用户Id查询task操作记录
     */

    @ApiOperation(value = "根据用户Id查询task操作记录", notes = "根据用户Id查询task操作记录")
    @RequestMapping(value = "/searchFinishTask", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<HistoricActivityInstance>> page(
            @RequestParam Integer pageNo,
            @RequestParam Integer pageSize) {
        return Result.ok(tChangNameDanService.searchFinshTask(pageNo, pageSize));
    }



    /**一：使用流程实例ID，查找请假单ID，从而获取请假单信息*/

    @ApiOperation(value = "使用任务ID，查找请假单ID，从而获取请假单信息", notes = "使用任务ID，查找请假单ID，从而获取请假单信息")
    @RequestMapping(value = "/detailFinishTask/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "processInstanceId ", dataType = "String", paramType = "path")
    public Result<TChangNameDan> detailFinishTask(@PathVariable("id") Integer id) {
        return Result.ok(tChangNameDanService.detailFinishTask(id));
    }

}





























